﻿using Perspective.Wpf3D.Primitives;
using Perspective.Wpf3D.Sculptors;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;

namespace Perspective.Wpf3D.Shapes
{
    /// <summary>
    /// 梯子
    /// A 3D Ladder element.
    /// By default, the direction of the arrow is the Z axis, and the length is 1.0.
    /// Default radius of the body is 0.1.
    /// Default radius of the head is 0.2.
    /// </summary>
    public class Ladder3D : GeometryElement3D
    {
        /// <summary>
        /// Static constructor.
        /// </summary>
        static Ladder3D()
        {
            // No default back material for 3D closed shapes.
            BackMaterialProperty.OverrideMetadata(
                typeof(Ladder3D),
                new PropertyMetadata(
                    null,
                    VisualPropertyChanged));
        }

        /// <summary>
        /// Called by UIElement3D.InvalidateModel() to update the 3D model.
        /// </summary>
        protected override void OnUpdateModel()
        {
            Sculptor = new LadderSculptor(Length,Width,StepHeight,LongRadius,ShortRadius);

            base.OnUpdateModel();
        }

        #region Length 梯子长度

        /// <summary>
        /// Gets or sets the axis length.
        /// </summary>
        public double Length
        {
            get { return (double)GetValue(LengthProperty); }
            set { SetValue(LengthProperty, value); }
        }

        /// <summary>
        /// Identifies the Length dependency property.
        /// Default value is 1.0.
        /// </summary>
        public static readonly DependencyProperty LengthProperty =
            DependencyProperty.Register(
                "Length",
                typeof(double),
                typeof(Ladder3D),
                new PropertyMetadata(
                    LadderSculptor.DefaultLength,
                    VisualPropertyChanged));

        #endregion

        #region Width 梯子宽度
        /// <summary>
        /// Gets or sets the axis Width.
        /// </summary>
        public double Width
        {
            get { return (double)GetValue(WidthProperty); }
            set { SetValue(WidthProperty, value); }
        }

        /// <summary>
        /// Identifies the Width dependency property.
        /// Default value is 0.5.
        /// </summary>
        public static readonly DependencyProperty WidthProperty =
            DependencyProperty.Register(
                "Width",
                typeof(double),
                typeof(Ladder3D),
                new PropertyMetadata(
                    LadderSculptor.DefaultWidth,
                    VisualPropertyChanged));
        #endregion

        #region StepHeight 每节横杆高度
        /// <summary>
        /// Gets or sets the axis StepHeight.
        /// </summary>
        public double StepHeight
        {
            get { return (double)GetValue(StepHeightProperty); }
            set { SetValue(StepHeightProperty, value); }
        }

        /// <summary>
        /// Identifies the StepHeight dependency property.
        /// Default value is 0.5.
        /// </summary>
        public static readonly DependencyProperty StepHeightProperty =
            DependencyProperty.Register(
                "StepHeight",
                typeof(double),
                typeof(Ladder3D),
                new PropertyMetadata(
                    LadderSculptor.DefaultStepHeight,
                    VisualPropertyChanged));
        #endregion

        #region LongRadius 梯子长杆半径
        /// <summary>
        /// Gets or sets the axis LongRadius.
        /// </summary>
        public double LongRadius
        {
            get { return (double)GetValue(LongRadiusProperty); }
            set { SetValue(LongRadiusProperty, value); }
        }

        /// <summary>
        /// Identifies the LongRadius dependency property.
        /// Default value is 0.05.
        /// </summary>
        public static readonly DependencyProperty LongRadiusProperty =
            DependencyProperty.Register(
                "LongRadius",
                typeof(double),
                typeof(Ladder3D),
                new PropertyMetadata(
                    LadderSculptor.DefaultLongRadius,
                    VisualPropertyChanged));
        #endregion

        #region ShortRadius 梯子横杆半径
        /// <summary>
        /// Gets or sets the axis ShortRadius.
        /// </summary>
        public double ShortRadius
        {
            get { return (double)GetValue(ShortRadiusProperty); }
            set { SetValue(ShortRadiusProperty, value); }
        }

        /// <summary>
        /// Identifies the ShortRadius dependency property.
        /// Default value is 0.03.
        /// </summary>
        public static readonly DependencyProperty ShortRadiusProperty =
            DependencyProperty.Register(
                "ShortRadius",
                typeof(double),
                typeof(Ladder3D),
                new PropertyMetadata(
                    LadderSculptor.DefaultShortRadius,
                    VisualPropertyChanged));
        #endregion
    }
}
